package com.dmcloud.system.fegin;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.dmcloud.common.util.reponse.ResultMessage;
import com.dmcloud.system.entity.SysUser;
import com.dmcloud.system.feign.IUserClient;
import com.dmcloud.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by xiaodao
 * date: 2020/5/9
 */
@RestController
@RequestMapping("/user-fegin")
public class UserFeginController implements IUserClient {
    @Autowired
    private ISysUserService sysUserService;

    @RequestMapping("/info/{account}")
    public ResultMessage getUserInfo(@PathVariable("account") String account) {

        SysUser user = sysUserService.getOne(Wrappers.<SysUser>query().lambda().eq(SysUser::getAccount, account));
        if (null == user) {
            return ResultMessage.failed(String.format("用户名不存在 %s", account));
        }
        return ResultMessage.success(sysUserService.getUserInfo(user));
    }
}
